﻿function GetPersonListAction() {
    // extend IAction
    IAction.apply(this, []);

    this.do = function (args) {
        _includeHelper.resetInclude(_container, "Module/Person/Person.html");
        setTimeout(function () { _processPerson.doAction(args); }, 100);

        _historyHelper.update(args);
    }

    this.getName = function () {
        return 'GetPersonList';
    }
}

function AddPersonAction() {
    IAction.apply(this, []);

    this.do = function (state) {
        if ($(_container).attr("include") == undefined || $(_container).attr("include") != "Module/Person/Person.html") {
            _includeHelper.resetInclude(_container, "Module/Person/Person.html");
            setTimeout(function () { _processPerson.doAction({ action: "GetPersonList" }); }, 100);
        }
        setTimeout(function () {
            $("#txt_person_id").val("");
            $("#txt_person_name").val("");
            $("#txt_person_birthday").val("");
            $("#txt_person_address").val("");
            $("#person_dialog").dialog("open");
        }, 500);
        _historyHelper.update(state);
    }

    this.getName = function () {
        return 'AddPerson';
    }
}

function EditPersonAction() {
    IAction.apply(this, []);

    this.do = function (state) {
        if ($(_container).attr("include") == undefined || $(_container).attr("include") != "Module/Person/Person.html") {
            _includeHelper.resetInclude(_container, "Module/Person/Person.html");
            window.setTimeout(function () {
                _processPerson.doAction({ action: "GetPersonList" });
            }, 100);
        }
        window.setTimeout(function () {
            _processPerson.doAction({ action: "GetPersonById", id: state.id }, function (person) {
                $("#txt_person_id").val(person.id);
                $("#txt_person_name").val(person.name);
                $("#txt_person_birthday").val(person.birthday);
                $("#txt_person_address").val(person.address);
                $("#person_dialog").dialog("open");
            });
        }, 300);
        _historyHelper.update(state);
    }

    this.getName = function () {
        return 'EditPerson';
    }
}

function DeletePersonAction() {
    IAction.apply(this, []);

    this.do = function (state) {
        _processPerson.doAction(state);
        _historyHelper.update({ action: "GetPersonList" });
    }

    this.getName = function () {
        return 'DeletePerson';
    }
}

function GetDetailAction() {
    var that = this;
    IAction.apply(this, []);

    this.do = function (state) {
        if ($(_container).attr("include") == undefined || $(_container).attr("include") != "Module/Person/Person_detail.html") {
            _includeHelper.resetInclude(_container, "Module/Person/Person_detail.html");
            window.setTimeout(function () {
                _processPerson.doAction(state);
            }, 100);
        } else {
            window.setTimeout(function () {
                _processPerson.doAction(state);
            }, 300)
        }
        _historyHelper.update(state);
    }
    this.getName = function () {
        return 'DetailPerson';
    }
}

function GetBookListAction() {
    IAction.apply(this, []);

    this.do = function (args) {
        _includeHelper.resetInclude(_container, "Module/Book/Book.html");
        setTimeout(function () {
            _processBook.doAction(args);
        }, 100);
        _historyHelper.update(args);
    }

    this.getName = function () {
        return 'GetBookList';
    }
}

function Chat() {
    IAction.apply(this, []);
    this.do = function (args) {
        _includeHelper.resetInclude(_container, "Module/Chat/Chat.html");
        _historyHelper.update(args);
    }

    this.getName = function () {
        return 'Chat';
    }
}